package com.xiaoshuidi.cloud.module.report.controller.datamanage;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.report.controller.datamanage.vo.*;
import com.xiaoshuidi.cloud.module.report.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.report.service.datamanage.UserPortraitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.Map;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

/**
 * 用户画像
 */
@Slf4j
@Validated
@RestController
@RequestMapping(ApiConstants.DATA_MANAGE + "/user-portrait")
public class UserPortraitController {

    @Resource
    private UserPortraitService userPortraitService;

    @PostMapping("/rent-distribution")
    @Operation(summary = "在租租客租金分布")
    @Parameters({
            @Parameter(name = "apartmentId", description = "门店id", required = false),
            @Parameter(name = "includCohabitants", description = "是否包含同住人", required = true),
    })
    public CommonResult<RentDistributionRespVO> rentDistribution(@RequestBody UserPortraitReqVO reqVO){
        return success(userPortraitService.rentDistribution(reqVO.getApartmentIds(), reqVO.getIncludCohabitants()));
    }

    @PostMapping("/age-distribution")
    @Operation(summary = "在租租客年龄、性别分布")
    @Parameters({
            @Parameter(name = "apartmentId", description = "门店id", required = false),
            @Parameter(name = "includCohabitants", description = "是否包含同住人", required = true),
    })
    public CommonResult<AgeSexDistributionRespVO> ageSexDistribution(@RequestBody UserPortraitReqVO reqVO){
        return success(userPortraitService.ageSexDistribution(reqVO.getApartmentIds(), reqVO.getIncludCohabitants()));
    }

    @PostMapping("/region-distribution")
    @Operation(summary = "在租租客地域分布")
    @Parameters({
            @Parameter(name = "apartmentId", description = "门店id", required = false),
            @Parameter(name = "includCohabitants", description = "是否包含同住人", required = true),
    })
    public CommonResult<Map<String, Long>> regionDistribution(@RequestBody UserPortraitReqVO reqVO){
        return success(userPortraitService.regionDistribution(reqVO.getApartmentIds(), reqVO.getIncludCohabitants()));
    }

    @PostMapping("/card-type-distribution")
    @Operation(summary = "在租租客证件类型分布")
    @Parameters({
            @Parameter(name = "apartmentId", description = "门店id", required = false),
            @Parameter(name = "includCohabitants", description = "是否包含同住人", required = true),
    })
    public CommonResult<Map<String, Long>> cardTypeDistribution(@RequestBody UserPortraitReqVO reqVO){
        return success(userPortraitService.cardTypeDistribution(reqVO.getApartmentIds(), reqVO.getIncludCohabitants()));
    }
}
